package controller

import (
	"bookmark-web/middleware"

	"github.com/gin-gonic/gin"
)

// getUserID 从JWT中间件获取当前用户ID
func getUserID(c *gin.Context) uint {
	userID, exists := middleware.GetUserIDFromContext(c)
	if !exists {
		// 如果无法获取用户ID，返回0（这种情况不应该发生，因为有中间件保护）
		return 0
	}
	return userID
}

// getUsername 从JWT中间件获取当前用户名
func getUsername(c *gin.Context) string {
	username, exists := middleware.GetUsernameFromContext(c)
	if !exists {
		return ""
	}
	return username
}

// requireAuth 检查用户是否已认证
func requireAuth(c *gin.Context) bool {
	userID := getUserID(c)
	return userID > 0
}
